package top.chatgqt.SmartChargeStation.demo.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.chatgqt.SmartChargeStation.demo.mqtt.PahoMode.service.ClientService;

@RestController
public class MqttPahoController {

    @Resource
    private ClientService clientService;

    // 发布
    @RequestMapping(value = "/paho/pub")
    public void pahoPub(
            @RequestParam String topic,
            @RequestParam String message) {
        clientService.publish(topic, message);

        clientService.disconnect();
    }

    // 订阅
    @RequestMapping(value = "/paho/sub")
    public void pahoSub(@RequestParam String topic) {
        clientService.subScribe(topic);

        clientService.disconnect();
    }
}
